'\" te
.\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
.\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH RPCGEN 1 "Dec 16, 2013"
.SH NAME
rpcgen \- an RPC protocol compiler
.SH SYNOPSIS
.LP
.nf
\fBrpcgen\fR \fIinfile\fR
.fi

.LP
.nf
\fBrpcgen\fR [\fB-a\fR] [\fB-A\fR] [\fB-b\fR] [\fB-C\fR] [\fB-D\fR \fIname\fR [= \fIvalue\fR]] [\fB-i\fR \fIsize\fR]
     [\fB-I\fR [\fB-K\fR \fIseconds\fR]] [\fB-L\fR] [\fB-M\fR] [\fB-N\fR] [\fB- T\fR] [\fB-v\fR]
     [\fB-Y\fR \fIpathname\fR] \fIinfile\fR
.fi

.LP
.nf
\fBrpcgen\fR [\fB-c\fR | \fB-h\fR | \fB-l\fR | \fB-m\fR | \fB-t\fR | \fB-Sc\fR | \fB-Ss\fR | \fB-Sm\fR]
     [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
.fi

.LP
.nf
\fBrpcgen\fR [\fB-s\fR \fInettype\fR] [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
.fi

.LP
.nf
\fBrpcgen\fR [\fB-n\fR \fInetid\fR] [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
.fi

.SH DESCRIPTION
.sp
.LP
The \fBrpcgen\fR utility is a tool that generates C code to implement an
\fBRPC\fR protocol. The input to \fBrpcgen\fR is a language similar to C known
as \fBRPC\fR Language (Remote Procedure Call Language).
.sp
.LP
The \fBrpcgen\fR utility is normally used as in the first synopsis where it
takes an input file and generates four output files. If the \fIinfile\fR is
named \fBproto.x\fR, then \fBrpcgen\fR generates a header in \fBproto.h\fR,
\fBXDR\fR routines in \fBproto_xdr.c\fR, server-side stubs in
\fBproto_svc.c\fR, and client-side stubs in \fBproto_clnt.c\fR. With the
\fB-T\fR option, it also generates the \fBRPC\fR dispatch table in
\fBproto_tbl.i\fR.
.sp
.LP
\fBrpcgen\fR can also generate sample client and server files that can be
customized to suit a particular application. The \fB-Sc\fR, \fB-Ss\fR, and
\fB-Sm\fR options generate sample client, server and makefile, respectively.
The \fB-a\fR option generates all files, including sample files. If the infile
is \fBproto.x\fR, then the client side sample file is written to
\fBproto_client.c\fR, the server side sample file to \fBproto_server.c\fR and
the sample makefile to \fBmakefile.proto\fR.
.sp
.LP
The server created can be started both by the port monitors (for example,
\fBinetd\fR or \fBlisten\fR) or by itself. When it is started by a port
monitor, it creates servers only for the transport for which the file
descriptor \fB0\fR was passed. The name of the transport must be specified by
setting up the environment variable \fBPM_TRANSPORT\fR. When the server
generated by \fBrpcgen\fR is executed, it creates server handles for all the
transports specified in the \fBNETPATH\fR environment variable, or if it is
unset, it creates server handles for all the visible transports from the
\fB/etc/netconfig\fR file. Note: the transports are chosen at run time and not
at compile time. When the server is self-started, it backgrounds itself by
default. A special define symbol \fBRPC_SVC_FG\fR can be used to run the server
process in foreground.
.sp
.LP
The second synopsis provides special features which allow for the creation of
more sophisticated \fBRPC\fR servers. These features include support for
user-provided \fB#defines\fR and \fBRPC\fR dispatch tables. The entries in the
\fBRPC\fR dispatch table contain:
.RS +4
.TP
.ie t \(bu
.el o
pointers to the service routine corresponding to that procedure
.RE
.RS +4
.TP
.ie t \(bu
.el o
a pointer to the input and output arguments
.RE
.RS +4
.TP
.ie t \(bu
.el o
the size of these routines
.RE
.sp
.LP
A server can use the dispatch table to check authorization and then to execute
the service routine. A client library can use the dispatch table to deal with
the details of storage management and \fBXDR\fR data conversion.
.sp
.LP
The other three synopses shown above are used when one does not want to
generate all the output files, but only a particular one. See the EXAMPLES
section below for examples of \fBrpcgen\fR usage. When \fBrpcgen\fR is executed
with the \fB-s\fR option, it creates servers for that particular class of
transports. When executed with the \fB-n\fR option, it creates a server for the
transport specified by \fInetid\fR. If \fIinfile\fR is not specified,
\fBrpcgen\fR accepts the standard input.
.sp
.LP
All the options mentioned in the second synopsis can be used with the other
three synopses, but the changes are made only to the specified output file.
.sp
.LP
The C preprocessor \fBcc\fR \fB-E\fR is run on the input file before it is
actually interpreted by \fBrpcgen\fR. For each type of output file,
\fBrpcgen\fR defines a special preprocessor symbol for use by the \fBrpcgen\fR
programmer:
.sp
.ne 2
.na
\fB\fBRPC_HDR\fR\fR
.ad
.RS 12n
defined when compiling into headers
.RE

.sp
.ne 2
.na
\fB\fBRPC_XDR\fR\fR
.ad
.RS 12n
defined when compiling into \fBXDR\fR routines
.RE

.sp
.ne 2
.na
\fB\fBRPC_SVC\fR\fR
.ad
.RS 12n
defined when compiling into server-side stubs
.RE

.sp
.ne 2
.na
\fB\fBRPC_CLNT\fR\fR
.ad
.RS 12n
defined when compiling into client-side stubs
.RE

.sp
.ne 2
.na
\fB\fBRPC_TBL\fR\fR
.ad
.RS 12n
defined when compiling into \fBRPC\fR dispatch tables
.RE

.sp
.LP
Any line beginning with ``\fB%\fR'' is passed directly into the output file,
uninterpreted by \fBrpcgen\fR, except that the leading ``\fB%\fR" is stripped
off. To specify the path name of the C preprocessor, use the \fB-Y\fR flag.
.sp
.LP
For every data type referred to in \fIinfile\fR, \fBrpcgen\fR assumes that
there exists a routine with the string \fBxdr_\fR prepended to the name of the
data type. If this routine does not exist in the \fBRPC\fR/\fBXDR\fR library,
it must be provided. Providing an undefined data type allows customization of
\fBXDR\fR routines.
.SS "Server Error Reporting"
.sp
.LP
By default, errors detected by \fBproto_svc.c\fR is reported to standard error
and/or the system log.
.sp
.LP
This behavior can be overridden by compiling the file with a definition of
\fBRPC_MSGOUT\fR, for example, \fB-DRPC_MSGOUT=mymsgfunc\fR. The function
specified is called to report errors. It must conform to the following
\fBprintf\fR-like signature:
.sp
.in +2
.nf
extern void RPC_MSGOUT(const char *fmt, ...);
.fi
.in -2
.sp

.SH OPTIONS
.sp
.LP
The following options are supported:
.sp
.ne 2
.na
\fB\fB-a\fR\fR
.ad
.RS 18n
Generates all files, including sample files.
.RE

.sp
.ne 2
.na
\fB\fB-A\fR\fR
.ad
.RS 18n
Enables the Automatic \fBMT\fR mode in the server main program. In this mode,
the \fBRPC\fR library automatically creates threads to service client requests.
This option generates multithread-safe stubs by implicitly turning on the
\fB-M\fR option. Server multithreading modes and parameters can be set using
the \fBrpc_control\fR(3NSL) call. \fBrpcgen\fR generated code does not change
the default values for the Automatic \fBMT\fR mode.
.RE

.sp
.ne 2
.na
\fB\fB-b\fR\fR
.ad
.RS 18n
Backward compatibility mode. Generates transport-specific \fBRPC\fR code for
older versions of the operating system.
.RE

.sp
.ne 2
.na
\fB\fB-c\fR\fR
.ad
.RS 18n
Compiles into \fBXDR\fR routines.
.RE

.sp
.ne 2
.na
\fB\fB-C\fR\fR
.ad
.RS 18n
Generates header and stub files which can be used with ANSI C compilers.
Headers generated with this flag can also be used with C++ programs.
.RE

.sp
.ne 2
.na
\fB\fB-D\fR\fIname\fR\fB[=\fR\fIvalue\fR\fB]\fR\fR
.ad
.RS 18n
Defines a symbol \fIname\fR. Equivalent to the \fB#define\fR directive in the
source. If no \fIvalue\fR is given, \fIvalue\fR is defined as \fB1\fR. This
option can be specified more than once.
.RE

.sp
.ne 2
.na
\fB\fB-h\fR\fR
.ad
.RS 18n
Compiles into \fBC\fR data-definitions (a header). The \fB-T\fR option can be
used in conjunction to produce a header which supports \fBRPC\fR dispatch
tables.
.RE

.sp
.ne 2
.na
\fB\fB-i\fR \fIsize\fR\fR
.ad
.RS 18n
Size at which to start generating inline code. This option is useful for
optimization. The default \fIsize\fR is 5.
.RE

.sp
.ne 2
.na
\fB\fB-I\fR\fR
.ad
.RS 18n
Compiles support for \fBinetd\fR(8) in the server side stubs. Such servers can
be self-started or can be started by \fBinetd\fR. When the server is
self-started, it backgrounds itself by default. A special define symbol
\fBRPC_SVC_FG\fR can be used to run the server process in foreground, or the
user can simply compile without the \fB-I\fR option.
.sp
If there are no pending client requests, the \fBinetd\fR servers exit after 120
seconds (default). The default can be changed with the \fB-K\fR option. All of
the error messages for \fBinetd\fR servers are always logged with
\fBsyslog\fR(3C).
.sp
\fBNote:\fR This option is supported for backward compatibility only. It should
always be used in conjunction with the \fB-b\fR option which generates backward
compatibility code. By default (that is, when \fB-b\fR is not specified),
\fBrpcgen\fR generates servers that can be invoked through portmonitors.
.RE

.sp
.ne 2
.na
\fB\fB-K\fR \fIseconds\fR\fR
.ad
.RS 18n
By default, services created using \fBrpcgen\fR and invoked through port
monitors wait 120 seconds after servicing a request before exiting. That
interval can be changed using the \fB-K\fR flag. To create a server that exits
immediately upon servicing a request, use \fB-K\fR \fB0\fR. To create a server
that never exits, the appropriate argument is \fB-K\fR \fB\(mi1\fR\&.
.sp
When monitoring for a server, some portmonitors, like \fBlisten\fR(8),
\fBalways\fR spawn a new process in response to a service request. If it is
known that a server are used with such a monitor, the server should exit
immediately on completion. For such servers, \fBrpcgen\fR should be used with
\fB-K\fR \fB0\fR.
.RE

.sp
.ne 2
.na
\fB\fB-l\fR\fR
.ad
.RS 18n
Compiles into client-side stubs.
.RE

.sp
.ne 2
.na
\fB\fB-L\fR\fR
.ad
.RS 18n
When the servers are started in foreground, uses \fBsyslog\fR(3C) to log the
server errors instead of printing them on the standard error.
.RE

.sp
.ne 2
.na
\fB\fB-m\fR\fR
.ad
.RS 18n
Compiles into server-side stubs, but do not generate a "main" routine. This
option is useful for doing callback-routines and for users who need to write
their own "main" routine to do initialization.
.RE

.sp
.ne 2
.na
\fB\fB-M\fR\fR
.ad
.RS 18n
Generates multithread-safe stubs for passing arguments and results between
\fBrpcgen\fR-generated code and user written code. This option is useful for
users who want to use threads in their code.
.RE

.sp
.ne 2
.na
\fB\fB-N\fR\fR
.ad
.RS 18n
This option allows procedures to have multiple arguments. It also uses the
style of parameter passing that closely resembles C. So, when passing an
argument to a remote procedure, you do not have to pass a pointer to the
argument, but can pass the argument itself. This behavior is different from the
old style of \fBrpcgen\fR-generated code. To maintain backward compatibility,
this option is not the default.
.RE

.sp
.ne 2
.na
\fB\fB-n\fR \fInetid\fR\fR
.ad
.RS 18n
Compiles into server-side stubs for the transport specified by \fInetid\fR.
There should be an entry for \fInetid\fR in the \fBnetconfig\fR database. This
option can be specified more than once, so as to compile a server that serves
multiple transports.
.RE

.sp
.ne 2
.na
\fB\fB-o\fR \fIoutfile\fR\fR
.ad
.RS 18n
Specifies the name of the output file. If none is specified, standard output is
used (\fB-c\fR, \fB-h\fR, \fB-l\fR, \fB-m\fR, \fB-n\fR, \fB-s\fR, \fB-Sc\fR,
\fB-Sm\fR, \fB-Ss\fR, and \fB-t\fR modes only).
.RE

.sp
.ne 2
.na
\fB\fB-s\fR \fInettype\fR\fR
.ad
.RS 18n
Compiles into server-side stubs for all the transports belonging to the class
\fInettype\fR. The supported classes are \fBnetpath\fR, \fBvisible\fR,
\fBcircuit_n\fR, \fBcircuit_v\fR, \fBdatagram_n\fR, \fBdatagram_v\fR,
\fBtcp\fR, and \fBudp\fR (see \fBrpc\fR(3NSL) for the meanings associated with
these classes). This option can be specified more than once. \fBNote:\fR The
transports are chosen at run time and not at compile time.
.RE

.sp
.ne 2
.na
\fB\fB-Sc\fR\fR
.ad
.RS 18n
Generates sample client code that uses remote procedure calls.
.RE

.sp
.ne 2
.na
\fB\fB-Sm\fR\fR
.ad
.RS 18n
Generates a sample Makefile which can be used for compiling the application.
.RE

.sp
.ne 2
.na
\fB\fB-Ss\fR\fR
.ad
.RS 18n
Generates sample server code that uses remote procedure calls.
.RE

.sp
.ne 2
.na
\fB\fB-t\fR\fR
.ad
.RS 18n
Compiles into \fBRPC\fR dispatch table.
.RE

.sp
.ne 2
.na
\fB\fB-T\fR\fR
.ad
.RS 18n
Generates the code to support \fBRPC\fR dispatch tables.
.sp
The options \fB-c\fR, \fB-h\fR, \fB-l\fR, \fB-m\fR, \fB-s\fR, \fB-Sc\fR,
\fB-Sm\fR, \fB-Ss\fR, and \fB-t\fR are used exclusively to generate a
particular type of file, while the options \fB-D\fR and \fB-T\fR are global and
can be used with the other options.
.RE

.sp
.ne 2
.na
\fB\fB-v\fR\fR
.ad
.RS 18n
Displays the version number.
.RE

.sp
.ne 2
.na
\fB\fB-Y\fR \fIpathname\fR\fR
.ad
.RS 18n
Gives the name of the directory where \fBrpcgen\fR starts looking for the C
preprocessor.
.RE

.SH OPERANDS
.sp
.LP
The following operand is supported:
.sp
.ne 2
.na
\fB\fIinfile\fR\fR
.ad
.RS 10n
input file
.RE

.SH EXAMPLES
.LP
\fBExample 1 \fRGenerating the output files and dispatch table
.sp
.LP
The following entry

.sp
.in +2
.nf
example% \fBrpcgen -T prot.x\fR
.fi
.in -2
.sp

.sp
.LP
generates all the five files: \fBprot.h\fR, \fBprot_clnt.c\fR,
\fBprot_svc.c\fR, \fBprot_xdr.c\fR, and \fBprot_tbl.i\fR.

.LP
\fBExample 2 \fRSending headers to standard output
.sp
.LP
The following example sends the C data-definitions (header) to the standard
output:

.sp
.in +2
.nf
example% \fBrpcgen -h prot.x\fR
.fi
.in -2
.sp

.LP
\fBExample 3 \fRSending a test version
.sp
.LP
To send the test version of the \fB-DTEST\fR, server side stubs for all the
transport belonging to the class \fBdatagram_n\fR to standard output, use:

.sp
.in +2
.nf
example% \fBrpcgen -s datagram_n -DTEST prot.x\fR
.fi
.in -2
.sp

.LP
\fBExample 4 \fRCreating server side stubs
.sp
.LP
To create the server side stubs for the transport indicated by \fInetid\fR
\fBtcp\fR, use:

.sp
.in +2
.nf
example% \fBrpcgen -n tcp -o prot_svc.c prot.x\fR
.fi
.in -2
.sp

.SH EXIT STATUS
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 6n
Successful operation.
.RE

.sp
.ne 2
.na
\fB\fB>0\fR\fR
.ad
.RS 6n
An error occurred.
.RE

.SH SEE ALSO
.sp
.LP
.BR syslog (3C),
.BR rpc (3NSL),
.BR rpc_control (3NSL),
.BR rpc_svc_calls (3NSL),
.BR netconfig (5),
.BR attributes (7),
.BR inetd (8),
.BR listen (8)
.sp
.LP
The \fBrpcgen\fR chapter in the \fIONC+ Developer\&'s Guide\fR manual.
